package STACK_20;

import java.util.Stack;

public class Solution {
	public boolean isValid(String s) {
		char[] SA = s.toCharArray();
		Stack<Character> left = new Stack<Character>();
		for (char c : SA) {
			if (c == '(' || c == '{' || c == '[') {
				left.push(c);
			}else {
				if (!left.isEmpty() && left.peek() == leftOf(c)) {
					left.pop();
				}else {
					return false;
				}
			}
		}
		return left.isEmpty();
	}

	private Character leftOf(char c) {
		// TODO Auto-generated method stub
		if (c==')') {
			return '(';
		}
		if (c==']') {
			return '[';
		}
		return '{';
	}
}
